/**
 * Created by apple on 16/2/25.
 */
    
    
class Controller {
    constructor(systemService, $scope, $state, $rootScope) {
        "ngInject"
        this.state     = "";
        this.RE        = /corp|role|region|menu|dict/;
        $rootScope.isMenuLoad = false;
        systemService.getMenuUser().then((res) => {
            __DEBUG__ && console.log('menuLoad', Date.now())
            this.menus            = res.data.menus;
            $rootScope.user       = res.data.user;
            $rootScope.isMenuLoad = true;
            $rootScope.isUser     = true;
        })

        $scope.$watch(() => {
            return $state.current.url
        }, () => {
            if ($state.current.url.match(this.RE)) {
                this.state = $state.current.url.match(this.RE)[0]
            } else {
                this.state = $state.current.name;
            }
        })
    }

    checkUrl(url) {
        if (url.match(/https?/)) return 2;
        return 1;
    }

    toggleOpenMenu(menu) {
        menu.fold = !menu.fold
    }

    calcMenuHeight(menu) {
        return {
            height: 40 * menu.item.length
        }
    }
}

export default Controller;
